<!--新增考核指标-->
<template>
	<el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false">
		<el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" @keyup.enter="submitHandle()">
			<el-form-item label="主键" prop="id" v-if="false">
				<el-input v-model="dataForm.id" placeholder="主键"></el-input>
			</el-form-item>

			<el-form-item label="指标类型" prop="name">
				<el-tree-select
					v-model="dataForm.jjId"
					:data="jjList"
					value-key="id"
					check-strictly
					:render-after-expand="false"
					:props="{ value: 'id', label: 'name', children: 'children' }"
					style="width: 100%"
				/>
			</el-form-item>
			<el-form-item label="指标名称" prop="name">
				<el-input v-model="dataForm.remark" placeholder="备注"></el-input>
			</el-form-item>
			<el-form-item label="指标类别" prop="name">
				<el-tree-select
					v-model="dataForm.jjId"
					:data="jjList"
					value-key="id"
					check-strictly
					:render-after-expand="false"
					:props="{ value: 'id', label: 'name', children: 'children' }"
					style="width: 100%"
				/>
			</el-form-item>

			<el-form-item label="考核规则" prop="name">
				<el-input v-model="dataForm.remark" placeholder="备注" type="textarea"></el-input>
			</el-form-item>
			<el-form-item label="加分上限" prop="name">
				<el-input v-model="dataForm.remark" placeholder="备注"></el-input>
			</el-form-item>

			<el-form-item label="备注" prop="name">
				<el-input v-model="dataForm.remark" placeholder="备注" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button type="primary" @click="submitHandle()">保存</el-button>
			<el-button @click="visible = false">取消</el-button>
		</template>
	</el-dialog>
</template>

<style lang="scss" scoped>
.card-- {
	height: 100px;
	width: 100%;
	overflow-y: scroll;
}
.card-x {
	margin: 0px 10px 0px 0px;
	width: 1px;
	display: none;
}

.card-span button {
	margin-right: 10px;
}
.card-span:hover {
	card-t {
		margin-right: 0px;
	}
	.card-x {
		display: inline-grid;
		margin-right: 10px;
	}
}
</style>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElDatePicker, ElMessage, ElMessageBox, ElTimePicker } from 'element-plus/es'
import { useRoleApi } from '@/api/nb/organization/role'
import { findByPcode } from '@/api/nb/business/dictionaries_subset'

import constant from '@/utils/constant'
import type { UploadProps } from 'element-plus'

const emit = defineEmits(['refreshDataList'])

const visible = ref(false)
const dataFormRef = ref()
let staffList = reactive({
	data: [
		{ name: '小昭12', id: 12 },
		{ name: '小昭13', id: 13 },
		{ name: '小昭14', id: 14 },
		{ name: '小昭15', id: 15 },
		{ name: '小昭16', id: 16 },
		{ name: '小昭17', id: 17 },
		{ name: '小昭18', id: 18 },
		{ name: '小昭19', id: 19 },
		{ name: '小昭21', id: 21 },
		{ name: '小昭22', id: 22 }
	]
})

//关闭 员工标签
const OffStaff = (id: number) => {
	ElMessageBox.confirm('确定进行删除操作?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	})
		.then(() => {
			let aa = staffList.data.filter(item => {
				return item.id != id
			})

			staffList.data = aa
		})
		.catch(() => {})
}

const dataForm = reactive({
	id: '',

	name: '',
	startDate: '',
	startTime: '',
	endDate: '',
	endTime: '',
	jjId: '',
	remark: '',
	dbId: '',
	url: ''
})

const init = (id?: number) => {
	visible.value = true
	dataForm.id = ''

	// 重置表单数据
	if (dataFormRef.value) {
		dataFormRef.value.resetFields()
	}

	if (id) {
		getRole(id)
	}
	getDbList()
	getJjList()
}

const getRole = (id: number) => {
	useRoleApi(id).then(res => {
		Object.assign(dataForm, res.data)
	})
}

// 获取 待办提醒
const dbList = ref({})
const getDbList = () => {
	return findByPcode('DaiBanTiXing').then(res => {
		dbList.value = res.data.list
	})
}
// 获取 紧急程度
const jjList = ref({})
const getJjList = () => {
	return findByPcode('JinJiChengDu').then(res => {
		jjList.value = res.data.list
	})
}

const dataRules = ref({})

// 表单提交
const submitHandle = () => {
	dataFormRef.value.validate((valid: boolean) => {
		if (!valid) {
			return false
		}

		emit('refreshDataList')
		// useRoleSubmitApi(dataForm).then(() => {
		// 	ElMessage.success({
		// 		message: '操作成功',
		// 		duration: 500,
		// 		onClose: () => {
		// 			visible.value = false
		// 			emit('refreshDataList')
		// 		}
		// 	})
		// })
	})
}

//上传附件
const fileDataForm = reactive({
	name: '',
	platform: '',
	size: '',
	url: ''
})

const handleSuccess: UploadProps['onSuccess'] = (res, file) => {
	if (res.code !== 0) {
		ElMessage.error('上传失败：' + res.msg)
		return false
	}

	Object.assign(fileDataForm, res.data)

	dataForm.url = fileDataForm.url
}

const beforeUpload: UploadProps['beforeUpload'] = file => {
	if (file.size / 1024 / 1024 / 1024 / 1024 > 1) {
		ElMessage.error('文件大小不能超过100M')
		return false
	}
	return true
}

defineExpose({
	init
})
</script>
